﻿//-------------------------------------------------------------------------------------------------
// <copyright file="Program.cs" company="BeeWix">
// BeeWix. Licensed under MIT
// </copyright>
//-------------------------------------------------------------------------------------------------

namespace ConsoleTest
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using BeeWix.Toolkit.NoSql.Neo4J.Cypher;
    using BeeWix.Toolkit.NoSql.Neo4J;
    using System.Diagnostics;
    
    /// <summary>
    /// Main class of the console app.
    /// </summary>
    public class Program
    {
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args">List of arguments</param>
        private static void Main(string[] args)
        {
            var lst = CypherEngine.Query<UserBeewix>(@"start n=node:UserBeewix(Type = ""UserBeewix"") return n;");
            
            foreach(var itm in lst)
            {
                Console.WriteLine(itm.ToJson());
                Console.WriteLine("Delete item : " +  CypherEngine.DeleteNode(itm, true));
            }
            
            var Francois       = CypherEngine.CreateNode<UserBeewix>();
            Francois.Name      = "François Skorzec";
            Francois.Age       = 32;
            Francois.BirthDate = new DateTime(1979,10,25);

            var Stephanie       = CypherEngine.CreateNode<UserBeewix>();
            Stephanie.Name      = "Stépanie Skorzec";
            Stephanie.Age       = 32;
            Stephanie.BirthDate = new DateTime(1980,03,27);

            var Mathys       = CypherEngine.CreateNode<UserBeewix>();
            Mathys.Name      = "Mathys Skorzec";
            Mathys.Age       = 3;
            Mathys.BirthDate = new DateTime(2008,12,16);

            CypherEngine.UpdateNodeProperties(Francois,true);
            Console.WriteLine("Update ok");
            CypherEngine.UpdateNodeProperties(Stephanie,true);
            Console.WriteLine("Update ok");
            CypherEngine.UpdateNodeProperties(Mathys,true);
            Console.WriteLine("Update ok");

            Console.WriteLine(CypherEngine.CreateRelationship(Francois,Stephanie,"MARIED"));
            Console.WriteLine(CypherEngine.CreateRelationship(Francois,Mathys,"FATHER"));

            Console.WriteLine(CypherEngine.CreateRelationship(Stephanie,Francois,"MARIED"));
            Console.WriteLine(CypherEngine.CreateRelationship(Stephanie,Mathys,"MOTHER"));

            Console.WriteLine(CypherEngine.CreateRelationship(Mathys,Stephanie,"SON"));
            Console.WriteLine(CypherEngine.CreateRelationship(Mathys,Francois,"SON"));
        }
    }

    public class UserBeewix : Neo4JNode
    {
        [Neo4JNodeIndex("UserBeewix")]
        public string Type{ get { return "UserBeewix"; } set{} }
        [Neo4JNodeIndex("UserBeewix")]
        public string Name { get; set; }
        public int Age { get; set; }
        public DateTime BirthDate { get; set; }
    }
}
